package sws.alex.run;

import java.util.Random;

import android.graphics.Bitmap;
import android.graphics.Canvas;

@SuppressWarnings("unused")
public class Enemy extends Sprite {
	private int screenWidth, screenHeight;
	private int frameWidth, frameHeight;
	private boolean isAlive;
	
	Random r;
	
	public Enemy(Bitmap bitmap, int frameWidth, int frameHeight){
		super(bitmap,frameWidth,frameHeight);
		this.frameWidth = frameWidth;
		this.frameHeight = frameHeight;
		defineReferencePixel(frameWidth/2, frameHeight/2);
		
		r = new Random();
	}
	
	public void setScreenSize(int screenWidth, int screenHeight){
		this.screenWidth = screenWidth;
		this.screenHeight = screenHeight;
	}
	
	public void setAlive(boolean alive){
		this.isAlive = alive;
		if(isAlive){
			int x = (r.nextInt() & 0x7fffffff)%(screenWidth-frameWidth);
			setPosition(x,0);
		}
	}
	
	public void move(){
		if(isAlive){
			move(0,3);
			if(getY()>screenHeight) isAlive = false;
		}
	}
	
	public boolean isAlive(){
		return isAlive;
	}
	
	public void draw(Canvas c){
		if(isAlive) paint(c);
	}
	
}
